﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TiTi.tea.DAL;
using TiTi.tea.Model;

namespace TiTi.tea.BLL
{
    public class SkuBLL
    {
        private SkuDAL skuDal = new SkuDAL();

        /// <summary>
        /// 根据规格文字获取
        /// </summary>
        /// <param name="spuId"></param>
        /// <param name="specStr"></param>
        /// <returns></returns>
        public Sku GetBySpec(int spuId,string specStr)
        {
            return GetBySpuId(spuId).FirstOrDefault(o => o.Spec == specStr);
        }

        /// <summary>
        /// 根据spuId获取sku
        /// </summary>
        /// <param name="spuId"></param>
        /// <returns></returns>
        public IEnumerable<Sku> GetBySpuId(int spuId)
        {
            return skuDal.GetAll(o=>o.SpuId== spuId);
        }

        /// <summary>
        /// 根据id获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Sku GetById(int id)
        {
            return skuDal.GetOne(o=>o.Id == id);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sku"></param>
        /// <returns></returns>
        public bool Update(Sku sku)
        {
            sku.UpdateTime = DateTime.Now;
            return skuDal.Update(sku);
        }
    }
}
